//
// Created by cmo on 2022/3/20.
//
#pragma once
#include <thread>
#include <pthread.h>

using namespace std;
#include "safe_queue_tool.h"

SafeQueue<int> q;

void *get(void* args) {
    while (1) {
        int i;
        q.consume(i);
        cout << "消费:"<< i << endl;
        if(-1==i)
        {
            printf("全部执行完毕，退出...\n");
            break;
        }
    }
    return 0;
}
void *put(void* args) {
    while (1)
    {
        int i;
        printf("请输入你要的数据...\n");
        cin >> i;
        q.produce(i);
        if(-1==i)
        {
            printf("全部执行完毕，退出...\n");
            break;
        }
    }
    return 0;
}
int test()
{
    pthread_t pid1, pid2;
    pthread_create(&pid1, 0, get, &q);
    pthread_create(&pid2, 0, put, &q);
    pthread_join(pid2,0);
    system("pause");
    return 0;
}

